import { _decorator, Color, Component, Node, Sprite, SpriteFrame } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Card')
export class Card extends Component {


    @property(Boolean)
    public clickable:boolean=true;

    @property(Boolean)
    public isInWait:boolean=false;

    @property(Number)
    public val:number=1;

    @property(SpriteFrame )
    public bg1: SpriteFrame = null!
    @property(SpriteFrame )
    public bg2: SpriteFrame = null!
    @property(SpriteFrame )
    public bg3: SpriteFrame = null!
    @property(SpriteFrame )
    public bg4: SpriteFrame = null!
    @property(SpriteFrame )
    public bg5: SpriteFrame = null!
    @property(SpriteFrame )
    public bg6: SpriteFrame = null!

    
    
    start() {
        //设置卡牌背景为val值
        let background=this.node.getComponent(Sprite)
        if(background!=null){
            background.spriteFrame=this['bg'+this.val]
        }
    }

    update(deltaTime: number) {
        //设置卡牌可点击为正常颜色，不可点击为灰色
        let background=this.node.getComponent(Sprite)
        if(background!=null){
            background.color=this.clickable||this.isInWait?new Color(255, 255, 255, 255) : new Color(150, 137, 137, 255)
        }
    }
}

